package com.dykj.fireFighting.server.socialUnit.devicemanger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dykj.fireFighting.api.socialUnit.devicemanger.entity.PartitionsDevice;
import com.dykj.fireFighting.api.socialUnit.devicemanger.service.IPartitionsDeviceService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.server.socialUnit.devicemanger.mapper.PartitionsDeviceMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 分区设备中间表
 *
 * @Author JacksonTu
 * @Date  2021-07-15 11:25:03
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class PartitionsDeviceServiceImpl extends BaseServiceImpl<PartitionsDeviceMapper, PartitionsDevice> implements IPartitionsDeviceService {
    @Autowired
    private PartitionsDeviceMapper partitionsDeviceMapper;
    @Override
    public List<PartitionsDevice> getDevices(String partitionId) {
        QueryWrapper<PartitionsDevice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("partition_id",partitionId);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional
    public int insertDevicePoint(String partitionId, List<PartitionsDevice> partitionsDeviceList) {
        QueryWrapper<PartitionsDevice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("partition_id",partitionId);
        baseMapper.delete(queryWrapper);
        return partitionsDeviceMapper.insertBatch(partitionsDeviceList);
    }
    @Override
    @Transactional
    public int insertPoint(PartitionsDevice partitionsDevice) {
        QueryWrapper<PartitionsDevice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("partition_id",partitionsDevice.getPartitionId());
        queryWrapper.eq("device_id",partitionsDevice.getDeviceId());
        baseMapper.delete(queryWrapper);
        return partitionsDeviceMapper.insert(partitionsDevice);
    }
    @Override
    public List<PartitionsDevice> getList(String partitionId){
        QueryWrapper<PartitionsDevice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("partition_id",partitionId);
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public PartitionsDevice getPoint(String partitionId, String deviceId) {
        QueryWrapper<PartitionsDevice> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("partition_id",partitionId);
        queryWrapper.eq("device_id",deviceId);
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Boolean deletePoint( String deviceId) {
        return this.baseMapper.deletePoint(deviceId);
    }

}
